package com.mxpio.erp.workshop.service.impl;

import com.mxpio.erp.common.workshop.entity.OoInNotice;
import com.mxpio.erp.common.workshop.entity.OoInNoticeLine;
import com.mxpio.erp.common.workshop.entity.OutsourceOrder;
import com.mxpio.erp.common.workshop.service.OoInNoticeService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.system.service.impl.BaseServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service
public class OoInNoticeServiceImpl extends BaseServiceImpl<OoInNotice> implements OoInNoticeService {
    @Override
    @Transactional
    public Result<List<OoInNotice>> listByIds(String noticeNos) {
        if (StringUtils.isBlank(noticeNos)){
            return Result.error("查询参数为空");
        }
        String[] split = noticeNos.split(",");
        List<String> noticeNoList = Stream.of(split).collect(Collectors.toList());
        List<OoInNotice> list = JpaUtil.linq(OoInNotice.class)
                .collect("noticeNo", OoInNoticeLine.class, "noticeNo")
                .collect("bizNo", OutsourceOrder.class,"bizOrderNo")
                .in("noticeNo", noticeNoList).list();
        return Result.OK(list);
    }
}
